package com.fayuan.nocv.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fayuan.nocv.entity.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    @Select("select mid from role_menu where rid = #{roleId}")
    List<Integer> queryMidByRid(Integer roleId);
    //分配菜单栏之前删除所有的rid数据
    @Delete("delete from role_menu where rid = #{rid}")
    void deleteRoleByRid(Integer rid);
    //根据获取到的rid和mid分配新的菜单栏权限
    @Insert("insert into role_menu(rid,mid) values (#{rid},#{mid})")
    void saveRoleMenu(Integer rid, Integer mid);
    //根据用户id查询所有该用户的角色
    @Select("select rid from user_role where uid = #{id}")
    List<Integer> queryUserRoleById(Integer id);
    //分配菜单栏之前删除所有的uid数据
    @Delete("delete from user_role where uid = #{uid}")
    void deleteUserRoleByUId(Integer uid);
    //根据获取到的uid和rid分配新的菜单栏权限
    @Insert("insert into user_role(uid,rid) values (#{uid},#{rid})")
    void saveUserRole(Integer uid, Integer rid);
}
